package intnet;

import java.net.Inet4Address;
import java.net.InetAddress;

public class test {
	public static void main(String[] args) {

		try {
			// 查询本机地址
			InetAddress aTest = InetAddress.getByName("127.0.0.1");
			System.out.println(aTest);
			InetAddress aTest2 = InetAddress.getByName("localhost");
			System.out.println(aTest2);
			InetAddress aTest3 = InetAddress.getLocalHost();
			System.out.println(aTest2);

			// 查询百度地址
			InetAddress aTest1 = InetAddress.getByName("www.baidu.com");
			System.out.println(aTest1);

			//常用方法
			System.out.println(aTest1.getAddress());
			System.out.println(aTest1.getCanonicalHostName());
			System.out.println(aTest1.getHostAddress());
			System.out.println(aTest1.getHostName());
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}

	}
}